﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using DWF.Studio.ISerivces;
using DWF.Studio.ScriptEngine.Custom;
using DWF.Studio.ScriptEngine.IPC;
using DWF.Studio.ScriptEngine.IPC.Msg;
using DWF.Studio.ScriptEngine.IPC.WorkFlow;
using DWF.Studio.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.Script.Excutor
{
    internal abstract class RemoteScriptExecutorBase : IScriptExecutor
    {
        public Action<ScriptExcuteAbortedEventArgs> ExecuteAborted
        {
            get;
            set;
        }

        public Action<ScriptExcuteCompletedEventArgs> ExecuteCompleted
        {
            get;
            set;
        }

        public Action<ScriptExcuteUnhandledExceptionEventArgs> ExecuteOnUnhandledException
        {
            get;
            set;
        }

        public Action<ScriptExecuteTrackEventArgs> ExecuteTrack
        {
            get;
            set;
        }

        public Action<FrameInfoBase> DebugTrack
        {
            get;
            set;
        }

        public Action<HitBreakpointEventArgs> HitBreakpoint
        {
            get;
            set;
        }

        public Action<ExecuteStartEventArgs> ExecuteStart
        {
            get;
            set;
        }

        public Action<ExecuteEndEventArgs> ExecuteEnd
        {
            get;
            set;
        }

        public Action<SubScriptExecuteStartEventArgs> SubScriptExecuteStart
        {
            get;
            set;
        }

        public Action<SubScriptExecuteEndEventArgs> SubScriptExecuteEnd
        {
            get;
            set;
        }

        //多组启动参数 Oliver 2021-06-24
        protected void getStartupProperties(Dictionary<string, string> projectProperties, string scriptPath)
        {
            projectProperties.Add(StartupProperties.Sysconfig.IsLogToFile, ConfigService.CurrentSysConfig.IsLogToFile ? "1" : "0");
            projectProperties.Add(StartupProperties.Sysconfig.IsConsoleOutToFile, ConfigService.CurrentSysConfig.IsConsoleOutToFile ? "1" : "0");
            projectProperties.Add(StartupProperties.Sysconfig.IsSilentExecution, ConfigService.CurrentSysConfig.IsSilentExecution ? "1" : "0");
            var projectName = projectProperties["projectName"];
            projectProperties.Add(StartupProperties.ScriptPath.projectName, projectName);
            projectProperties.Add(StartupProperties.ScriptPath.scriptFileName_WithoutExtension, System.IO.Path.GetFileNameWithoutExtension(scriptPath));
        }

        public abstract void Cancel();

        public abstract string Debug(string projectDirectory, string scriptPath, bool isStepOver);

        public abstract string Debug(string projectDirectory, string scriptPath, Dictionary<string, object> param, bool isStepOver);

        public abstract void Dispose();

        public abstract string Execute(string projectDirectory, string scriptPath);

        public abstract string Execute(string projectDirectory, string scriptPath, Dictionary<string, object> param);

        public abstract void DebugResume();

        public abstract void DebugStepInto();

        public abstract void DebugStepOut();

        public abstract void DebugStepOver();

        public abstract void RefreshBreakpoint(string scriptPath);

        public abstract void CallDebugInfos();

        public abstract void SetLoadAssemblyNames(string[] assemblyNames);

        public abstract void SetSearchPaths(string[] paths);

        public abstract void SetProjectProperties(Func<Dictionary<string, string>> projectPropertiesFunc);
    }
}
